package cn.bijy.sqlsession;


import cn.bijy.config.XMLConfigerBuilder;
import cn.bijy.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        Configuration configuration = new Configuration();
        //解析配置文件，封装Configuration
        XMLConfigerBuilder xmlConfigerBuilder = new XMLConfigerBuilder(configuration);
        xmlConfigerBuilder.parseConfiguration(inputStream);
        //创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
